<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组的开发技巧</title>
</head>
<body>
    
    <script>

        // 数组内数字的随机排序
        +function () {
            function aryRandomSort (ary) {
                return ary.sort((a,b)=>{
                    console.log(Math.random() - 0.5);
                    return Math.random() - 0.5;
                });
            }

            console.log(aryRandomSort([1,2,3,4,5,6,7]));
        } ();


               
        //  取出数组的随机项目

        +function () {

            let ary = [1,2,3,4,5,6];
            let num = Math.floor(Math.random()*(ary.length));
            console.log(ary[num]);

        } ();

        // 获取数组中最大和最小的项目

        +function () {

            let arr = [1,2,3,4,5,6];
            let max = Math.max.apply(null,arr);
            let min = Math.min.apply(null,arr);
            console.log(max,min);

        } ();

        // 清空数组

        +function () {

            let ary = [1,2,3,4,5,6];

            ary.length = 0;

            console.log(ary);


        } ();
    </script>
</body>
</html>